<template>
  <div class="tree-layout">
            <div class="tree">
                <div class="reflash" @click="reflash()"><span class="el-icon-refresh">刷新</span> </div>
                <el-tree 
                :data="treeData" ref="cmsSiteTree" :props="props"  @node-click="nodeClik"  :default-expanded-keys="['']"   :indent="16" node-key="id"></el-tree>
            </div>
  </div>
</template>

<script>
import axios from "axios";
export default {
  data() {
    return {
        props: {
          label: "name",
          children: "child",
          isLeaf: "hasChild",
          id: "id"
        },
        treeData:[{
          name: '根目录',
          id: '',
          child:[],
          hasChild:true,
        }],
        status:false
    };
  },
  methods: {
      initData() {
        axios.post(this.$api.departmentTree,{root: ''}).then(res => {
         
          if(res.body.length > 0 ){
            let data=[{
          name: '根目录',
          id: '',
          child:[],
          hasChild:true,
        }]
        data[0].child=res.body
        this.treeData=data
         
          }
       }); 
    },
    nodeClik(data){
      this.$emit("node-click",data);
    },
    reflash(){
      this.initData();
    }
  },
  created(){
    this.initData();
  }
};
</script>

<style>

</style>
